package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MaintenanceRecord;
import com.ruoyi.system.service.IMaintenanceRecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 维修记录（含申请功能）Controller
 * 
 * @author ruoyi
 * @date 2025-07-01
 */
@Controller
@RequestMapping("/system/record")
public class MaintenanceRecordController extends BaseController
{
    private String prefix = "system/record";

    @Autowired
    private IMaintenanceRecordService maintenanceRecordService;

    @RequiresPermissions("system:record:view")
    @GetMapping()
    public String record()
    {
        return prefix + "/record";
    }

    /**
     * 查询维修记录（含申请功能）列表
     */
    @RequiresPermissions("system:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MaintenanceRecord maintenanceRecord)
    {
        startPage();
        List<MaintenanceRecord> list = maintenanceRecordService.selectMaintenanceRecordList(maintenanceRecord);
        return getDataTable(list);
    }

    /**
     * 导出维修记录（含申请功能）列表
     */
    @RequiresPermissions("system:record:export")
    @Log(title = "维修记录（含申请功能）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MaintenanceRecord maintenanceRecord)
    {
        List<MaintenanceRecord> list = maintenanceRecordService.selectMaintenanceRecordList(maintenanceRecord);
        ExcelUtil<MaintenanceRecord> util = new ExcelUtil<MaintenanceRecord>(MaintenanceRecord.class);
        return util.exportExcel(list, "维修记录（含申请功能）数据");
    }

    /**
     * 新增维修记录（含申请功能）
     */
    @RequiresPermissions("system:record:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存维修记录（含申请功能）
     */
    @RequiresPermissions("system:record:add")
    @Log(title = "维修记录（含申请功能）", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MaintenanceRecord maintenanceRecord)
    {
        return toAjax(maintenanceRecordService.insertMaintenanceRecord(maintenanceRecord));
    }

    /**
     * 修改维修记录（含申请功能）
     */
    @RequiresPermissions("system:record:edit")
    @GetMapping("/edit/{maintenanceId}")
    public String edit(@PathVariable("maintenanceId") Long maintenanceId, ModelMap mmap)
    {
        MaintenanceRecord maintenanceRecord = maintenanceRecordService.selectMaintenanceRecordByMaintenanceId(maintenanceId);
        mmap.put("maintenanceRecord", maintenanceRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存维修记录（含申请功能）
     */
    @RequiresPermissions("system:record:edit")
    @Log(title = "维修记录（含申请功能）", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MaintenanceRecord maintenanceRecord)
    {
        return toAjax(maintenanceRecordService.updateMaintenanceRecord(maintenanceRecord));
    }

    /**
     * 删除维修记录（含申请功能）
     */
    @RequiresPermissions("system:record:remove")
    @Log(title = "维修记录（含申请功能）", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(maintenanceRecordService.deleteMaintenanceRecordByMaintenanceIds(ids));
    }
}
